package com.ly.hotel.view.fragments.vod;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.ly.hotel.R;
import com.ly.hotel.model.Vodpart;
import com.ly.hotel.util.LanguageUtil;

import java.util.List;

public class VodHeadAdapter extends BaseAdapter {
	Context mContext;
	LayoutInflater mInflater;
	private List<Vodpart> vodHeadName;
	private int selectedPosition = -1;

	public VodHeadAdapter(Context c, List<Vodpart> vodHeadName) {
		this.vodHeadName = vodHeadName;
		mContext = c;
		mInflater = LayoutInflater.from(mContext);
	}

	@Override
	public int getCount() {
		return vodHeadName.size();
	}

	@Override
	public Object getItem(int postion) {
		return vodHeadName.get(postion);
	}

	@Override
	public long getItemId(int postion) {
		return postion;
	}
	
	public void setSelectedPosition(int position) {
        selectedPosition = position;
		notifyDataSetChanged();
    }

	// 终端：电影点播中点击类别，当前已选类别应突出
	@Override
	public View getView(int postion, View contentView, ViewGroup arg2) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		View view;
		if (contentView == null) {
			holder = new ViewHolder();
			view = mInflater.inflate(R.layout.vod_btn_item, null);
			holder.mbtn = (TextView) view.findViewById(R.id.m_vod_item_btn);
			view.setTag(holder);
		} else {
			view = contentView;
			holder = (ViewHolder) view.getTag();
		}
		if(postion == selectedPosition){
			holder.mbtn.setTextColor(Color.parseColor("#00DFFF"));
		}else{
			holder.mbtn.setTextColor(Color.rgb(255,255,255));
		}
		holder.mbtn.setText(LanguageUtil.getTextFromLocalLanguage(vodHeadName.get(postion).getVodpartname().replace("TV_", "")));
		holder.v = vodHeadName.get(postion);
		return view;
	}

	static class ViewHolder {
		TextView mbtn;
		Vodpart v;
	}
}
